﻿using Microsoft.VisualStudio.TestTools.UITest.Common;

namespace AXExtension.Filters
{
	/// <summary>
	/// Allows for persistent instances of the filters, so
	/// that they can use past information to inform current
	/// actions.
	/// </summary>
	class FilterGroup
	{
		private Filter[] filters;

		public FilterGroup(params Filter[] filters)
		{
			this.filters = filters;
		}

		public void Run(IUITestActionStack stack)
		{
			foreach (var filter in filters)
			{
				filter.UnconditionalRun(stack);
				bool requirementsSatisfied = true;
				foreach (var requirement in filter.Requirements)
				{
					requirementsSatisfied = requirementsSatisfied && requirement(stack);
				}
				if (requirementsSatisfied)
				{
					filter.Run(stack);
				}
			}
		}
	}
}
